#!/bin/bash -e

function info() {
echo Usage: `basename $0` 'list'
exit 1
}

while getopts  ":p:f:" opt; do
	case  $opt  in
		p) out_prefix=$OPTARG;;
		f) suffix=$OPTARG;;
		*) info;;
	esac
done
shift $(($OPTIND - 1))


if [ $# -lt 1 ]; then info; fi

. $var

export PATH=~/yn/tools/conda/bin:$PATH
. activate t27

# awk '$2~/^[01]/' $1 > $1.clear

# rf_pre_merge_site.sh -p$out_prefix $1.clear 10000

# rf_methy.sh -p$out_prefix $out_prefix.test.merge.100.3.txt $out_prefix.b450k.site_merge.random_site.txt
list=$1
bed1=/mnt/ilustre/app/medical/data/adm/interval.bed
bed=/mnt/ilustre/users/fei.yang/data/intervals/1/b37.1_22.bed
target=/mnt/ilustre/app/medical/data/adm/target.1960.bed
ref=/mnt/ilustre/app/medical/data/adm/ref1960.vcf
# interval=1.realn.intervals

cut -f1 $list > $out_prefix.list.samples

IFS=$'\n'
for i in `cat $list`; do
    
    nam=`echo $i|cut -f1`
    
    r1=`echo $i|cut -f2`
    r2=`echo $i|cut -f3`
    echo $nam
    echo $i 
    base=$out_prefix.$nam
    cutadp.sh -p$base $r1 $r2
    aln0818.sh -s$nam -p$out_prefix.$nam -b$bed $base.1.cut.fastq $base.2.cut.fastq
    
    # realign_bt.sh -i $bed -r$interval -p$base $i
    deldup.sh -m -p$base $base.sort.bam
    recal0630.sh -l $bed -p$base $base.markdup.bam
    hap.sh -p$base.1 $base.realn.recal.bam $bed1
       
done



. $cmd_done